package net.meblabs.bookapp.web.controller;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import net.meblabs.bookapp.util.ServiceLoaderUtil;
import net.meblabs.bookimp.AuthorImporter;
import net.meblabs.commons.progress.Progress;
import net.meblabs.commons.progress.ProgressRegistry;
import net.meblabs.commons.progress.comm.InitProgressMessage;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/import")
public class ImportController {

	private Map<String, AuthorImporter> importers;

	public ImportController() {
		importers = new HashMap<String, AuthorImporter>();
		Collection<AuthorImporter> tmp = ServiceLoaderUtil.load(AuthorImporter.class);
		for (AuthorImporter importer : tmp) {
			importers.put(importer.getClass().getCanonicalName(), importer);
		}
	}

	@RequestMapping("/initProgress")
	public @ResponseBody
	InitProgressMessage init() {
		Progress progress = ProgressRegistry.createProgress();
		return new InitProgressMessage(progress.getId(), "Import autorów");
	}
}
